package com.isoft.mapper;

import com.isoft.entity.DfmeStlsEntity;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

@Mapper
public interface DfmeStlsMapper {

    @Insert("INSERT INTO MSG_META(SENDER, RECEIVER, SEQUENCE_NUMBER, DATE_TIME, MSG_TYPE, SUB_TYPE) VALUES(#{entity.meta.sender}, #{entity.meta.receiver}, #{entity.meta.sequenceNumber}, TO_TIMESTAMP(#{entity.meta.dateTime}, 'YYYYMMDDHH24MISS'), #{entity.meta.type}, #{entity.meta.subType})")
    @Options(useGeneratedKeys = true, keyProperty = "meta.msgId", keyColumn = "MSG_ID")
    void insertMeta(@Param("entity") DfmeStlsEntity entity);

    @Insert("INSERT INTO FLIGHT_BASE(" +
            "FLIGHT_ID, FLIGHT_ATTRIBUTE, FLIGHT_FILE_ID, FLIGHT_IDENTIFIER) " +
            "VALUES(" +
            "#{dflt.flightId,jdbcType=NUMERIC}, " +
            "#{dflt.flightAttribute,jdbcType=VARCHAR}, " +
            "#{dflt.flightFileId,jdbcType=VARCHAR}, " +
            "#{dflt.flightIdentifier,jdbcType=VARCHAR})")
    int insertFlightBase(DfmeStlsEntity entity);

    @Insert("INSERT INTO BAGGAGE_CLAIM(" +
            "FLIGHT_ID, BELT_NUMBER, BELT_CODE, ESTIMATED_START_TIME, " +
            "ESTIMATED_END_TIME, REAL_START_TIME, REAL_END_TIME, BELT_SECTION) " +
            "VALUES(" +
            "#{dflt.flightId,jdbcType=NUMERIC}, " +
            "#{dflt.stls.stnd.standNumber,jdbcType=VARCHAR}, " +
            "#{dflt.stls.stnd.code,jdbcType=VARCHAR}, " +
            "TO_TIMESTAMP(#{dflt.stls.stnd.estimatedStartTime,jdbcType=VARCHAR}, 'yyyymmddhh24miss'), " +
            "TO_TIMESTAMP(#{dflt.stls.stnd.estimatedEndTime,jdbcType=VARCHAR}, 'yyyymmddhh24miss'), " +
            "CASE WHEN #{dflt.stls.stnd.realStartTime,jdbcType=VARCHAR} IS NULL OR #{dflt.stls.stnd.realStartTime,jdbcType=VARCHAR} = '' THEN NULL ELSE TO_TIMESTAMP(#{dflt.stls.stnd.realStartTime,jdbcType=VARCHAR}, 'yyyymmddhh24miss') END, " +
            "CASE WHEN #{dflt.stls.stnd.realEndTime,jdbcType=VARCHAR} IS NULL OR #{dflt.stls.stnd.realEndTime,jdbcType=VARCHAR} = '' THEN NULL ELSE TO_TIMESTAMP(#{dflt.stls.stnd.realEndTime,jdbcType=VARCHAR}, 'yyyymmddhh24miss') END, " +
            "#{dflt.stls.stnd.btsc,jdbcType=VARCHAR})")
    int insertBaggageClaim(DfmeStlsEntity entity);
}